/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.portlet.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.portlet.service.ClpSerializer;
import com.portlet.service.nguyenlieuLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Thi
 */
public class nguyenlieuClp extends BaseModelImpl<nguyenlieu>
	implements nguyenlieu {
	public nguyenlieuClp() {
	}

	public Class<?> getModelClass() {
		return nguyenlieu.class;
	}

	public String getModelClassName() {
		return nguyenlieu.class.getName();
	}

	public String getPrimaryKey() {
		return _maNguyenLieu;
	}

	public void setPrimaryKey(String primaryKey) {
		setMaNguyenLieu(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return _maNguyenLieu;
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey((String)primaryKeyObj);
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("maNguyenLieu", getMaNguyenLieu());
		attributes.put("tenNguyenLieu", getTenNguyenLieu());
		attributes.put("ghiChu", getGhiChu());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		String maNguyenLieu = (String)attributes.get("maNguyenLieu");

		if (maNguyenLieu != null) {
			setMaNguyenLieu(maNguyenLieu);
		}

		String tenNguyenLieu = (String)attributes.get("tenNguyenLieu");

		if (tenNguyenLieu != null) {
			setTenNguyenLieu(tenNguyenLieu);
		}

		String ghiChu = (String)attributes.get("ghiChu");

		if (ghiChu != null) {
			setGhiChu(ghiChu);
		}
	}

	public String getMaNguyenLieu() {
		return _maNguyenLieu;
	}

	public void setMaNguyenLieu(String maNguyenLieu) {
		_maNguyenLieu = maNguyenLieu;

		if (_nguyenlieuRemoteModel != null) {
			try {
				Class<?> clazz = _nguyenlieuRemoteModel.getClass();

				Method method = clazz.getMethod("setMaNguyenLieu", String.class);

				method.invoke(_nguyenlieuRemoteModel, maNguyenLieu);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getTenNguyenLieu() {
		return _tenNguyenLieu;
	}

	public void setTenNguyenLieu(String tenNguyenLieu) {
		_tenNguyenLieu = tenNguyenLieu;

		if (_nguyenlieuRemoteModel != null) {
			try {
				Class<?> clazz = _nguyenlieuRemoteModel.getClass();

				Method method = clazz.getMethod("setTenNguyenLieu", String.class);

				method.invoke(_nguyenlieuRemoteModel, tenNguyenLieu);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getGhiChu() {
		return _ghiChu;
	}

	public void setGhiChu(String ghiChu) {
		_ghiChu = ghiChu;

		if (_nguyenlieuRemoteModel != null) {
			try {
				Class<?> clazz = _nguyenlieuRemoteModel.getClass();

				Method method = clazz.getMethod("setGhiChu", String.class);

				method.invoke(_nguyenlieuRemoteModel, ghiChu);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getnguyenlieuRemoteModel() {
		return _nguyenlieuRemoteModel;
	}

	public void setnguyenlieuRemoteModel(BaseModel<?> nguyenlieuRemoteModel) {
		_nguyenlieuRemoteModel = nguyenlieuRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _nguyenlieuRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_nguyenlieuRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			nguyenlieuLocalServiceUtil.addnguyenlieu(this);
		}
		else {
			nguyenlieuLocalServiceUtil.updatenguyenlieu(this);
		}
	}

	@Override
	public nguyenlieu toEscapedModel() {
		return (nguyenlieu)ProxyUtil.newProxyInstance(nguyenlieu.class.getClassLoader(),
			new Class[] { nguyenlieu.class }, new AutoEscapeBeanHandler(this));
	}

	public nguyenlieu toUnescapedModel() {
		return this;
	}

	@Override
	public Object clone() {
		nguyenlieuClp clone = new nguyenlieuClp();

		clone.setMaNguyenLieu(getMaNguyenLieu());
		clone.setTenNguyenLieu(getTenNguyenLieu());
		clone.setGhiChu(getGhiChu());

		return clone;
	}

	public int compareTo(nguyenlieu nguyenlieu) {
		String primaryKey = nguyenlieu.getPrimaryKey();

		return getPrimaryKey().compareTo(primaryKey);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof nguyenlieuClp)) {
			return false;
		}

		nguyenlieuClp nguyenlieu = (nguyenlieuClp)obj;

		String primaryKey = nguyenlieu.getPrimaryKey();

		if (getPrimaryKey().equals(primaryKey)) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return getPrimaryKey().hashCode();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(7);

		sb.append("{maNguyenLieu=");
		sb.append(getMaNguyenLieu());
		sb.append(", tenNguyenLieu=");
		sb.append(getTenNguyenLieu());
		sb.append(", ghiChu=");
		sb.append(getGhiChu());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(13);

		sb.append("<model><model-name>");
		sb.append("com.portlet.model.nguyenlieu");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>maNguyenLieu</column-name><column-value><![CDATA[");
		sb.append(getMaNguyenLieu());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>tenNguyenLieu</column-name><column-value><![CDATA[");
		sb.append(getTenNguyenLieu());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>ghiChu</column-name><column-value><![CDATA[");
		sb.append(getGhiChu());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private String _maNguyenLieu;
	private String _tenNguyenLieu;
	private String _ghiChu;
	private BaseModel<?> _nguyenlieuRemoteModel;
}